/*================================================================
*   Copyright (C) 2023 baichao All rights reserved.
*   
*   文件名称：main.cpp
*   创 建 者：baichao
*   创建日期：2023年11月23日
*   描    述：
*
================================================================*/

#include <cassert>
#include <iostream>
#include <string>

#include "status.h"

void TestOK() {
    Status s = Status::OK();
    assert(s.ok());
    assert(s.ToString() == "OK");
}

void TestNotFound() {
    Status s = Status::NotFound("Test message");
    assert(!s.ok());
    assert(s.IsNotFound());
    assert(s.ToString() == "NotFound: Test message");

}

void TestCorruption() {
    Status s = Status::Corruption("Test message");
    assert(!s.ok());
    assert(s.IsCorruption());
    assert(s.ToString() == "Corruption: Test message");
}

void TestNotSupported() {
    Status s = Status::NotSupported("Test message");
    assert(!s.ok());
    assert(s.IsNotSupportedError());
    assert(s.ToString() == "Not supported: Test message");
}

void TestInvalidArgument() {
    Status s = Status::InvalidArgument("Test message");
    assert(!s.ok());
    assert(s.IsInvalidArgument());
    assert(s.ToString() == "Invalid argument: Test message");
}

void TestIOError() {
    Status s = Status::IOError("Test message");
    assert(!s.ok());
    assert(s.IsIOError());
    assert(s.ToString() == "I/O error: Test message");
}

void TestCopyAndAssign() {
    // Copy constructor
    const Status s1 = Status::NotFound("test message");
    const Status s2(s1);
    assert(s1.ToString() == s2.ToString());

    // Assignment operator
    Status s3 = Status::Corruption("test message");
    s3 = s1;
    assert(s1.ToString() == s3.ToString());
}

int main() {
    TestOK();
    TestNotFound();
    TestCorruption();
    TestNotSupported();
    TestInvalidArgument();
    TestIOError();
    TestCopyAndAssign();

    std::cout << "All tests passed." << std::endl;
    return 0;
}
